package com.ganeshkrishnan.globald.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ganeshkrishnan.globald.abstracts.GenericDaoHibernate;
import com.ganeshkrishnan.globald.dao.CivResourceDao;
import com.ganeshkrishnan.globald.model.CivResource;

@Repository
@Transactional
public class CivResourceDaoHibernate extends GenericDaoHibernate<CivResource, Long> implements CivResourceDao {
	public CivResourceDaoHibernate() {
		super(CivResource.class);
	}

	/**
	 * This will returns Number of civics, amount of resource and kind of resource
	 */
 	@SuppressWarnings("unchecked")
	public List<CivResource> findAllResourcesByPersonID(Long PersonID) {
		return (List<CivResource>) getHibernateTemplate().find("from CivResource where ResType<6 and PersonID=?", PersonID);
	}

	@SuppressWarnings("unchecked")
	public CivResource findResourceByPerson(Long PersonID, int resType)
	{
		List<CivResource> list = getHibernateTemplate().find("from CivResource where PersonID=? and ResType=?", PersonID, resType);
				
		return list==null?null:list.get(0);
	}
	
	/**
	 * Use save method instead
	 */
	@Deprecated
	public CivResource UpdateResource(CivResource resource) {
		getHibernateTemplate().saveOrUpdate(resource);
		getHibernateTemplate().flush();
		return resource;
	}

	public CivResource getCivilians(int civType) {
		// TODO Auto-generated method stub
		return null;
	}

	public CivResource getResource(int resType) {
		// TODO Auto-generated method stub
		return null;
	}
	
}
